<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
            src="<c:url value="/static/js/common.js"/>"></script>       
<script>
	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							toolbar : [
									{
										id : listDisplayEId + '_btn_add',
										text : '新增',
										iconCls : 'icon-add',
										handler : function() {
											var new_win = window.open("<c:url value='/jsp/openIndexSun.jsp?url=/role/preSaveRole.do'/>","sun","width=1200px,height=600px,status=no,scrollbars=yes");
										    new_win.focus();
											
											$('#' + listDisplayEId).datagrid('reload');
										}
									},
									'-',
									{
										id : listDisplayEId + '_btn_edit',
										text : '修改',
										iconCls : 'icon-edit',
										handler : function() {
											var row = $('#' + listDisplayEId)
													.datagrid('getSelections');
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {
												var new_win =window.open("<c:url value='/jsp/openIndexSun.jsp?url=/role/preUpdateRole.do?roleId="+ row[0]["roleId"]+ "'/>",
																"sun",
																"width=1200px,height=600px,status=no,scrollbars=yes");
	                                            new_win.focus();
	                                            $('#'+listDisplayEId).datagrid('reload');
												$('#' + listDisplayEId).datagrid('reload');
											}
											$('#' + listDisplayEId).datagrid('clearSelections');
										}
									},
									'-',
									{
										id : listDisplayEId + '_btn_del',
										text : '删除',
										iconCls : 'icon-cancel',
										handler : function() {

											var row = $('#' + listDisplayEId).datagrid('getSelections');
											if (row.length == 0) {
												$.messager.alert('提示',
														'请选择一条记录操作！', 'info');
												return;
											} else {
												var str = "roleId="
														+ row[0]['roleId'];
												$.messager
														.confirm(
																'提示',
																'是否删除该条记录？',
																function(r) {
																	if (r) {
																		$
																				.ajax({
																					type : 'post',
																					url : "<c:url value='/role/deleteRole.do'/>",
																					data : str,
																					dataType : "json",//设置查询参数及提交路径
																					success : function(data) {
																						if (data.success) {
																							$.messager.alert("提示","删除成功！",'info');
																							$('#'+ listDisplayEId).datagrid('reload');
																						} else {
																							$.messager.alert("提示",data.msg,'warning');
																						}
																					},
																					error : function() {
																						$.messager
																								.alert("错误","系统错误，请联系管理员！",
																										'error');
																					}
																				});
																	}
																	$('#'+ listDisplayEId).datagrid('reload');
																});
											}

										}
									} ],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							},
							onClickRow : function(rowIndex) {
								$(".myrad").prop("checked", false);
								$(".myrad").eq(rowIndex).prop("checked", true);
							}
						});

	};
	$(document).ready(function() {
		initList('listDisplay');
	});
	function save(index) {
		//获取表格行数
		$('#listDisplay').datagrid('endEdit', index);
		var rows = $('#listDisplay').datagrid('getRows');
		var allData = rows[index];
		var str = "rows=" + JSON.stringify(allData);
		$.ajax({
			type : 'post',
			url : "<c:url value='/role/saveRole.do'/>",
			data : str,
			dataType : "json",
			success : function(data) {
				if (data.success) {
					$('#listDisplay').datagrid('reload');
					$.messager.alert("提示", "保存成功！", 'info');
				} else {
					$.messager.alert("提示", "保存失败！", 'warning');
				}
			},
			error : function() {
				$.messager.alert("提示", "提交失败！", 'error');
			}
		});

	}

	function formatRadio(value, rowData, rowIndex) {
		return value = "<input type='radio' class='myrad'  name='radioRole' />";
	}

	function editrow(index) {
		$('#listDisplay').datagrid('beginEdit', index);
	}

	//角色状态展示0：可用；1为锁定
	function formatDGField(value, row, index, field) {
		if (value == "Y") {
			return "有效";
		} else {
			return "无效";
		}
	}

	function searchInfo() {
		$('#listDisplay').datagrid('load', {
			roleName : $('#roleName').val(),
			isActive : $('#isActive').combobox('getValue')
		});

	}
</script>
</head>
<body>
	<form id="searchForm" name="searchForm" method="post">
		<table>
			<tr>
				<td>
					<div
						style="height: auto; width: 1180px; background: #fafafa; padding: 5px;"
						class="easyui-panel" title="角色查询" iconCls="icon-search"
						collapsible="true" minimizable="false" maximizable="false"
						closable="false">

						<div>

							角色名： <input type="text" id="roleName" name="roleName"></input>
							是否有效：<select id="isActive" class="easyui-combobox">
								<option value="Y">有效</option>
								<option value="N">无效</option>
							</select> &nbsp;&nbsp;
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input
								type="button" onclick="searchInfo()" value="查询">
						</div>

					</div>
				</td>
			</tr>
			<tr>
				<td>
		</table>
	</form>
	<div style="height: 12px;"></div>
	<table id="listDisplay" title="角色列表" singleSelect=true
		iconCls="icon-list" idField="id"
		url="<c:url value="/role/findRole.do"/>"
		style="width: 800px; width: 1180px;" loadMsg="请稍候......"
		pagination="true" pageSize="10"
		pageList="[10,20,30,40,50,100,150,200]" sortName="roleId"
		rownumbers="true" sortOrder="asc">
		<thead>
			<tr>
				<th field="radioRole" width="25" align="center"
					formatter="formatRadio"></th>
				<th field="roleId" width="80" sortable="true">ID</th>
				<th field="roleName" width="80" sortable="true" editor="text">
					角色名</th>
				<th field="menuName" width="120" sortable="true" editor="text">
					菜单</th>
				<th field="isActive" width="80" formatter="formatDGField"
					sortable="true" editor="text">是否有效</th>
				<th field="identity" width="80" 
                    sortable="true" editor="text">客户权限标识</th>

			</tr>
		</thead>
	</table>
</body>
</html>